package com.jinxiangyang.controller;


import com.jinxiangyang.annotation.OperateLog;
import com.jinxiangyang.domain.vo.OrderSalesVo;
import com.jinxiangyang.domain.vo.OrderVo;
import com.jinxiangyang.service.OrderInfoService;
import com.jinxiangyang.utils.enums.BusinessType;
import com.jinxiangyang.utils.enums.OperatorType;
import com.jinxiangyang.utils.result.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 订单表 订单表 前端控制器
 * </p>
 *
 * @author jinxiangyang
 * @since 2023-08-12
 */
@RestController
@RequestMapping("/orderInfo")
@Api(tags = "订单信息模块")
public class OrderInfoController {
    @Autowired
    private OrderInfoService orderInfoService;

    @GetMapping("/{pageNumber}/{pageSize}")
    @OperateLog(title = "订单信息模块",operatorType = OperatorType.ADMIN, businessType = BusinessType.OTHER)
    public AjaxResult getOrderInfoListByPage(@PathVariable  Integer pageNumber,@PathVariable Integer pageSize, OrderVo orderVo){
        HashMap<String, Object> orderVo1 = orderInfoService.findOrderVo(pageNumber,pageSize,orderVo);
        return AjaxResult.success(orderVo1);
    }
    @DeleteMapping("/{id}")
    @OperateLog(title = "订单信息模块",operatorType = OperatorType.ADMIN, businessType = BusinessType.DELETE)
    public AjaxResult deleteOrderInfo(@PathVariable Long id){
        return orderInfoService.deleteOrderVo(id)?AjaxResult.success("删除成功"):AjaxResult.error("删除失败");
    }

    @GetMapping("/monthlySales")
    @ApiOperation("每月销量")
    public AjaxResult getMonthlySales(){
        List<OrderSalesVo> list = orderInfoService.getMonthlySales();
        return AjaxResult.success(list);
    }
}

